package com.shushan.mixedexam.oralcalculation.bean;

import android.text.TextUtils;

import com.android.net.bean.NetBaseBean;
import com.shushan.util.ToolUtils;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

import java.util.ArrayList;
import java.util.List;

/**
 * @ClassName: OralCalculateExamBean
 * @Desciption: //口算考试数据bean
 * @author: zhangshihao
 * @date: 2018-07-26
 */
public class OralCalculateExamBean extends NetBaseBean {

    private List<OralCalculateExerciseBean> oralCalculateExerciseBeans = new ArrayList<>();
    public OralCalculatePaperInfoBean paperInfoBean;

    @Override
    public void initByJson(JSONObject jsonObject) throws JSONException {
        if(jsonObject == null){
            return;
        }
        
        JSONArray exerciseArr = jsonObject.optJSONArray("paper");
        if(exerciseArr != null && exerciseArr.length() > 0){
            for(int i=0;i<exerciseArr.length();i++){
                JSONObject jobj = exerciseArr.optJSONObject(i);
                OralCalculateExerciseBean exerciseBean = new OralCalculateExerciseBean();
                exerciseBean.initByJson(jobj);
                oralCalculateExerciseBeans.add(exerciseBean);
            }
        }

        JSONObject paperInfoObj = jsonObject.optJSONObject("reward");
        if(paperInfoObj != null) {
            paperInfoBean = new OralCalculatePaperInfoBean();
            paperInfoBean.initByJson(paperInfoObj);
        }
    }

    public List<OralCalculateExerciseBean> getOralCalculateExerciseBeans() {
        return oralCalculateExerciseBeans;
    }

    public boolean isNotDo(){
        if (ToolUtils.isListEmpty(oralCalculateExerciseBeans)) {
            return true;
        }

        for (OralCalculateExerciseBean exerciseBean : oralCalculateExerciseBeans) {
            if (!TextUtils.isEmpty(exerciseBean.my_answer)) {
                return false;
            }
        }

        return true;
    }
}
